import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.datasets import load_breast_cancer

# plotting params
spr = 1
spc = 2
spn = 0
plt.figure(figsize=[14, 6])

x, y = load_breast_cancer(return_X_y=True)
x = x[:, :10]

df = pd.DataFrame(x)
print(df.shape)
M, N = df.shape

# corr by seaborn
corr = df.corr()
spn += 1
plt.subplot(spr, spc, spn)
plt.title('Corr from pandas')
sns.heatmap(corr, annot=True)

# corr by self
df_mean = df.mean(axis=0)
df_center = df - df_mean
Cx = np.matmul(df_center.T, df_center) / M
df_std = df.std(axis=0).to_numpy()
df_std = df_std.reshape(-1, 1)
denom = np.matmul(df_std, df_std.T)
Cx /= denom
spn += 1
plt.subplot(spr, spc, spn)
plt.title('Corr from myself')
sns.heatmap(Cx, annot=True)

plt.show()
